	$(function() {
		//alert('ok');
		djt_tax_editIndex = undefined;
		
		$('#djt_tax_dg').datagrid({
	    	url:'../taxRate/querybypage',
	    	columns:[[
	    		{field:'',title:'',checkbox:true},
				{field:'step',title:'级数',width:'50',sortable:true},
				{field:'stepMin',title:'应纳税所得额最小值',width:'150',editor:{type:'numberbox',options:{required:true}}},
				{field:'stepMax',title:'应纳税所得额最大值',width:'150',
					formatter: function(value,row,index){
						 if (row.step==7){
							return '无上限';
						} else {
							return value;
						} 
					},
					editor:{type:'numberbox',options:{required:true}}},
				{field:'taxRates',title:'税率',width:'80',editor:{type:'numberbox',options:{required:true,precision:2}},sortable:true},
				{field:'quickDeduction',title:'速算扣除数',width:'120',editor:{type:'numberbox',options:{required:true}}},
				{field:'cutoffPoint',title:'起征点',width:'100',editor:{type:'numberbox',options:{required:true}}}
			]],
			fit:true,
	 	   	fitColumns:false,
	 	   	//隔行变色
	 	   	striped:true,
	  	  	nowrap:true,
			toolbar:'#taxtb',
			pagination:true,
			pageSize:7,
			pageList:[7],
			border:false,
			idFieid:'step',
			sortName:'step',
			sortOrder:'asc',
			onAfterEdit : function(rowIndex,rowData,changes){
				//var inserted = $('#djt_tax_dg').datagrid('getChanges','inserted');
				var updated = $('#djt_tax_dg').datagrid('getChanges','updated');
				var url = '';
				/*if(inserted.length > 0){
					url = '../taxRate/insert';
				}*/
				if(updated.length > 0){
					url = '../taxRate/update';
				}
				var djt_tax_rowData = JSON.stringify(rowData);
				$.post(url,{djt_tax_rowData},function(e){
					var info = JSON.parse(e);
					//console.log(info);
					if(info.success){
						$('#djt_tax_dg').datagrid('acceptChanges');
						$.messager.show({
							title:'成功',
							msg:info.msg,
						});
					}else{
						$('#djt_tax_dg').datagrid('rejectChanges');
						$.messager.alert('错误',info.msg,'error');
					}
				})
				djt_tax_editIndex = undefined;
				$('#djt_tax_dg').datagrid('unselectAll');
			},
			onDblClickRow : function(rowIndex,rowData){
				if(djt_tax_editIndex != undefined){
					$('#djt_tax_dg').datagrid('endEdit',djt_tax_editIndex);
					djt_tax_editIndex = undefined;
				}
				if(djt_tax_editIndex == undefined){
					$('#djt_tax_dg').datagrid('beginEdit',rowIndex);
					if(rowIndex==6){
						var dd = $('#djt_tax_dg').datagrid('getEditor',{index: rowIndex, field: 'stepMax'});
						$(dd.target).numberbox('disable');
					}
					djt_tax_editIndex = rowIndex;
				}
			}
		});
	});

	/*//增加
	function addtax(){
		if(djt_tax_editIndex != undefined){
			$('#djt_tax_dg').datagrid('endEdit',djt_tax_editIndex);
		}
		if(djt_tax_editIndex == undefined){
			$('#djt_tax_dg').datagrid('insertRow',{
				index : 0,
				row:{
					
				}
			});
			$('#djt_tax_dg').datagrid('beginEdit',0);
			djt_tax_editIndex = 0;
		}
	}*/
	
	//保存
	function savetax(){
		$('#djt_tax_dg').datagrid('endEdit',djt_tax_editIndex);
	}
	
	/*//删除
	function removetax(){
		var rows = $('#djt_tax_dg').datagrid('getSelections');
		if(rows.length > 0){
			$.messager.confirm('请确认','您确定要删除当前所有选中的项目吗？',function(r){
				if(r){
					var steps = [];
					for(var i = 0; i < rows.length; i++){
						steps.push(rows[i].step)
					}
					var djt_tax_rowData = JSON.stringify(steps);
					$.post('../taxRate/delete',{djt_tax_rowData},function(e){
						var info = JSON.parse(e);
						if(info.success){
							$('#djt_tax_dg').datagrid('load');
							$('#djt_tax_dg').datagrid('unselectAll');
							$.messager.show({
								title:'成功',
								msg:info.msg,
							});
						}else{
							$('#djt_tax_dg').datagrid('rejectChanges');
							$.messager.alert('错误',info.msg,'error');
						}
					})
					djt_tax_editIndex = undefined;
				}
			})
		}else{
			$.messager.alert('提示','请选择要删除的记录！','error');
		}
	}*/
	
	//编辑
	function edittax(){
		var rows = $('#djt_tax_dg').datagrid('getSelections');
		if(rows.length == 1){
			if(djt_tax_editIndex != undefined){
				$('#djt_tax_dg').datagrid('endEdit',djt_tax_editIndex);
			}
			if(djt_tax_editIndex == undefined){
				var index = $('#djt_tax_dg').datagrid('getRowIndex',rows[0]);
				$('#djt_tax_dg').datagrid('beginEdit',index);
				djt_tax_editIndex = index;
				$('#djt_tax_dg').datagrid('unselectAll');
			}
		}else{
			$.messager.show({
				title:'提示',
				msg:'一次只能编辑一行！',
			});
		}
	}
	
	//撤销编辑
	function rejecttax(){
		djt_tax_editIndex = undefined;
		$('#djt_tax_dg').datagrid('rejectChanges');
		$('#djt_tax_dg').datagrid('unselectAll');
	}